﻿/**
 * Created by Administrator on 2017/8/7.
 */
define(function () {
    var Paging = {
        name: 'page',
        template: ''
        + '<div class="c-page" >'
        + '    <div class="c-page-left left">显示 <span>1-{{pageRows}}</span> 条，共 <span>{{totalPages}}</span>页<span>{{totalRows}}</span> 条</div>'
        + ''
        + '    <div class="c-page-box">'
        + '        &nbsp;&nbsp;<Button type="primary" @click.stop="elevator">确定</Button>'
        + '    </div>'
        + '    <div class="c-page-box">'
        + '        <Page :total="totalRows" :page-size="pageRows" show-elevator ref="iuPage" @on-change="changePage"></Page>'
        + '    </div>'
        + '</div>',
        props: {
            totalRows: {
                type: Number
            },
            pageRows: {
                type: Number,
                required: true
            },
            index: {
                type: Number
            }
        },
        computed: {
            totalPages: function () {
                var tp = Math.ceil(this.totalRows / this.pageRows);
                return tp;
            }
        },
        data: function () {
            return {
                customerlist: [],
                //currentPage:1
                pageIndex: 1
            }
        },
        methods: {
            elevator: function () {
                var val = $(".ivu-page-options-elevator input")[this.index].value;
                var page = 1;
                if (val > this.totalPages) {
                    page = this.totalPages;
                } else if (val <= 0) {
                    page = 1;
                } else {
                    page = val;
                }
                this.$refs.iuPage.changePage(parseInt(page));
                //this.currentPage=parseInt(page);
            },
            changePage: function (pageIndex) {
                this.pageIndex = pageIndex;
                //触发searchData
                this.$emit("search-data", pageIndex);//通过 bus 触发数据查询事件.
            }
        }
    }
    return Paging
})
